Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structures for F3 circuit optimizations #303

Merged
merged 4 commits into from
Aug 7, 2023

Conversation

Praveen91299
Copy link
Contributor

@Praveen91299 Praveen91299 commented Aug 2, 2023

Currently the F3 circuit has O(N^2) depth and circuit gate count. Added in this commit:

  • linear depth scaling via reordering elimination of matrix entries as elucidated here: http://arxiv.org/abs/2106.13839
  • Fixed gate filtering to remove redundant gates, few parameter checks.

Further reduction can be achieved as follows:
A general mean-field unitary U is decomposed into givens rotations, determined by eliminating off-diagonal elements in the matrix representation of U. For N orbitals, we have $N(N-1)/2$ such eliminations/Givens rotations for a N orbital system. Each givens rotation is between adjacent qubits only and are efficient in terms of gates.

For Hamiltonians over 2N spin-orbitals, the Unitaries U constructed for F3 fragments, except the first one body fragment currently are spin-restricted by default. This means that the matrix representation of U has a block-diagonal form, i.e., $U = U_u * U_d$ can be written as a product of mean-field unitaries over spin up/down sectors separately. But in order to implement $U_u$ and $U_d$ efficiently by givens rotations over adjacent qubits, we would require either the fermion ordering to be uudd and not udud (default) (or) a different modified jordan-wigner. The F3 routines currently can be directly adapted by simply relabelling the final outputted tensors and unitaries, but this reordering would require the user to use state-preparation with a different qubit ordering/mapping, and start with the Hamiltonian with fermions/spins reordered.

I'm not sure how to proceed with adding this as tequila mostly uses spin udud as in openfermion and might mean changes up-stream (it's not clear what parts of the workflow would this affect).

@kottmanj
Copy link
Collaborator

kottmanj commented Aug 3, 2023

Hi Praveen,
Thanks a lot for the contribution. I'm busy with exams this week, but I'll try to get to it as soon as possible.
I think the tests currently fail because the Grouping methods (for them the givens rotations where originally introduced) are expecting udud. But that should be solvable.

@Praveen91299
Copy link
Contributor Author

Hey Jakob,
No worries, take your time and all the best with exams! I took a look at the checks. I had modified the output format of phi in the givens_rotation and filtered the angle rotations. So the tests have not been updated to reflect this. I will fix it.

@kottmanj
Copy link
Collaborator

kottmanj commented Aug 7, 2023

Amazing. Looks like you figured it out. I will merge for now as I think the changes work as intended.
So far they are however not integrated into the F3 framework, i.e. the current default is still "method=naive" and not "method=short". Issue is, as you described, that "method=short" only works for ReversedJordanWigner (i.e. JW with N times Up + N times down ordering, instead of the Odd-indicies down, even indices up ordering).

The Measurement optimization methods are currently not using the standard quantum chemistry library from tequila, were we have

mol1 = tq.Molecule(geometry, transformation="JordanWigner") # default
mol2 = tq.Molecule(geometry, transformation="ReversedJordanWigner")

H1 = mol1.make_hamiltonian() # in std JW
H2 = mol2.make_hamiltonian() # in Reversed order JW

with corresponding changes, the current changes (and also more of the functionality currently implemented for the grouping exclusively) could be introduced in the quantum chemistry classes, like this

U1 = mol1.make_orbital_rotation_circuit(matrix) # default of method is "naive"
U2 = mol2.make_givens_rotation_circuit(matrix) # default of method is "short"
U3 = mol1.make_orbital_rotation_circuit(matrix, method="short") # will raise Exception (not supported for standard JW, same for Molecules with BravyiKitaev)

The base class for the QuantumChemistry structures is here (probably useful to see: make_UR method):
https://github.com/tequilahub/tequila/blob/master/src/tequila/quantumchemistry/qc_base.py

I think an initial integration would look like

class QuantumChemistryBase:
...
...

    def make_orbital_rotation_circuit(self, matrix, method=None, *args, **kwargs):
         if method is None:
             method="naive"
             if  self.transformation.up_then_down:
                 method="short"
        
        if "jordan-wigner" in self.transformation.name.lower():
            return get_orb_rot(matrix, method = method, *args, **kwargs):
        else:
            raise NotImplementedError("orbital rotation circuit not implemented for {}\n assemble yourself with mol.make_UR(...)".format(self.transformation) )
        

In a second step one would need to step-by-step absorb the fermionic functionality from the grouping techniques into the QuantumChemistryBase class, and then use an object for this class for the grouping functionality.

@schoi839 flagging you here, since some of the changes might impact some of your work.
Tests are all passing, and as far as I see, there shouldn't be issues. But better to let you know that this was introduced here.

@kottmanj kottmanj changed the title F3 circuit optimizations Structures for F3 circuit optimizations Aug 7, 2023
@kottmanj kottmanj merged commit cdf5c3c into tequilahub:devel Aug 7, 2023
@kottmanj
Copy link
Collaborator

kottmanj commented Aug 7, 2023

Let me know if that makes sense (comment above) or if you have questions

@Praveen91299
Copy link
Contributor Author

Hey Jakob, apologies I forgot to get back to this earlier. Your suggestions make sense. The depth option "short" is only a reordering of the rotations and can be used as such.

I had a conversation with Seonghoon and we believe it's best left as it is at the moment as it's very specific to user implementation and best not tamper with the spin-orderings. We can leave it to the user to modify as required.

@kottmanj
Copy link
Collaborator

No worries, there wasn’t any hurry. I merged already, in that case we leave it like this, and I keep it in mind, in case anyone ever asks about this functionality. The necessary tools are now there thanks to you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants